package com.hula.onion.book.server.spider.platforms.yiminjinrong;

import com.hula.onion.book.server.common.CommonResponse;
import com.hula.onion.book.server.common.SpiderCommon;
import com.hula.onion.book.server.config.ResponseStatusEnum;
import com.hula.onion.book.server.utils.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by work on 2018/1/19.
 */
@Component("ymjrSpider")
public class YmjrSuoSpider extends SpiderCommon {

    private static final String LOGIN_AUTH_URL = "https://www.ymjr360.com/user/doLogin.html";

    @Autowired
    private YmjrSpiderHelper spiderHelper;

    @Override
    public CommonResponse execute() {
        //发送请求
        String loginAuthStr = HttpUtils.post(LOGIN_AUTH_URL,
                spiderHelper.installRequestParams(loginForm),
                getHttpContext());
        if (spiderHelper.checkLogin(loginAuthStr)) {
            return spiderHelper.parseAccountBalance(loginAuthStr);
        } else {
            return new CommonResponse(ResponseStatusEnum.ACCOUNT_ERROR);
        }
    }
}
